<template>
  <div>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onRowSelectChange="selectChange"
      columnsRef="jzySeries"
      :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>
  </div>
</template>

<script>
  import { dictionary } from '@/utils/dictMixin';
  import { getlist,doupdate } from '@/api/customerService/arbitration/index';
  const type = [
    {text: '弹窗', value: '1'},
    {text: '推送', value: '2'},
  ]
    export default {
      name: "index",
      mixins: [dictionary],
      components: {
      },
      data() {
        return{
          columns: this.createTableColumns(),
          fetchApi: getlist,
          fetchParams: null,
          visibleDrawer: false,
          title: '新增',
          type:'',
          rowSelectData: [],
        };
      },
      created() {
      },
      methods: {
        createTableColumns () {
          return [
            {
              title: '序号',
              dataIndex: 'index',
              width: 70,
              sorter: true,
              render: props => {
                return <span>{props.row.index + 1}</span>;
              }
            },
            {
              title: '类型',
              dataIndex: 'type',
              sorter: true,
              dictItems: type,
            },
            {
              title: '控车时效(h)',
              dataIndex: 'controlCarTime',
              sorter: true,
              editRequired:true,
              editPattern:/^\+?[1-9][0-9]*$/,
              defaultEditable:true,
              editable: true,
              onChange:(index,data)=>{
                this.changeDiscount(index,data)
              }
            },
            {
              title: '处理时效(h)',
              dataIndex: 'handleTime',
              sorter: true,
              editRequired:true,
              editPattern:/^\+?[1-9][0-9]*$/,
              defaultEditable:true,
              editable: true,
              onChange:(index,data)=>{
                this.changeDiscount(index,data)
              }
            },
            {
              title: '创建时间',
              dataIndex: 'createdAt',
              dateFormat: 'yyyy-MM-dd hh:mm:ss',
              sorter: true
            },
            {
              title: '修改人',
              dataIndex: 'updateName',
              sorter: true
            },
            {
              title: '修改时间',
              dateFormat: 'yyyy-MM-dd hh:mm:ss',
              dataIndex: 'updatedAt',
              sorter: true
            }
          ]
        },
        changeDiscount(index,data){
         const err=  this.$refs.table.GET_REQUIRED_ERROR() // 非空的判断
         const error= this.$refs.table.GET_FORMAT_ERROR() // 正则的判断
          if( !error && !err ){
            doupdate(data).then(res=>{
              if (res.resultCode === 200) {
                this.$notify.success({title: '提示信息',message:'操作成功!'});
                // 重新加载
                this.dialogClose();
              }else {
                this.$notify.error({title: '提示信息',message:res.errMsg||'操作失败!'});
                this.dialogClose();
              }
            })
          }
        },
        dialogClose(){
          // 重新加载
          this.fetchParams = { ...this.fetchParams };
        },
        selectChange(val) {
          console.log('val', val);
          this.rowSelectData = val;
        }
      }
    }
</script>

<style scoped>

</style>
